﻿@namespace Xms.Abp.Components

<Row Gutter="4" Style="width:100%;">
    @if (Value.Type == ConditionType.Condition)
    {
        <AntDesign.Col Span="9">
            <Select
                Disabled="ReadOnly"
                Size="small"
                TItem="ConditionField"
                TItemValue="string"
                LabelName="DisplayName"
                ValueName="Field"
                DataSource="Fields"
                PlaceHolder="请选择字段"
                @bind-Value="Value.Condition.Field"
                OnSelectedItemChanged="OnFieldChange" />
        </AntDesign.Col>
        @if (Value.Condition.CompareDataType == CompareDataType.Bool)
        {
            <AntDesign.Col Span="5">
                <Select
                    Disabled="ReadOnly"
                    Size="small"
                    TItem="CompareType"
                    TItemValue="CompareType"
                    PlaceHolder="请选择比较方式"
                    OnSelectedItemChanged="OnCompareTypeChange"
                    @bind-Value="Value.Condition.CompareType">
                    <SelectOptions>
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.Equals"
                            Label="等于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.NotEquals"
                            Label="不等于" />
                    </SelectOptions>
                </Select>
            </AntDesign.Col>
            <AntDesign.Col Span="10">
                @{
                    var boolValue = false;
                    if(!bool.TryParse(Value.Condition.Value, out boolValue))
                    {
                        Value.Condition.Value = boolValue.ToString();
                    }
                }
                <YesNoSwitch OnChange="OnBoolChange" @bind-Value="boolValue" Size="small" Disabled="ReadOnly" />
            </AntDesign.Col>
        }
        else if (Value.Condition.CompareDataType == CompareDataType.Int
            || Value.Condition.CompareDataType == CompareDataType.Long
            || Value.Condition.CompareDataType == CompareDataType.Double
            || Value.Condition.CompareDataType == CompareDataType.Float
            || Value.Condition.CompareDataType == CompareDataType.Decimal
            || Value.Condition.CompareDataType == CompareDataType.DateTime)
        {
            <AntDesign.Col Span="5">
                <Select
                    Disabled="ReadOnly"
                    Size="small"
                    TItem="CompareType"
                    TItemValue="CompareType"
                    PlaceHolder="请选择比较方式"
                    OnSelectedItemChanged="OnCompareTypeChange"
                    @bind-Value="Value.Condition.CompareType">
                    <SelectOptions>
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.Equals"
                            Label="等于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.NotEquals"
                            Label="不等于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.GreaterThan"
                            Label="大于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.LessThan"
                            Label="小于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.GreaterThanOrEqual"
                            Label="大于等于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.LessThanOrEqual"
                            Label="小于等于" />
                    </SelectOptions>
                </Select>
            </AntDesign.Col>
            <AntDesign.Col Span="10">
                @if (Value.Condition.CompareDataType == CompareDataType.Int || Value.Condition.CompareDataType == CompareDataType.Long)
                {
                    var longValue = 0L;
                    if(!long.TryParse(Value.Condition.Value, out longValue))
                    {
                        Value.Condition.Value = longValue.ToString();
                    }
                    <AntDesign.InputNumber
                        Disabled="ReadOnly"
                        Style="width:100%"
                        Size="small"
                        TValue="long"
                        OnChange="OnLongChange"
                        @bind-Value="longValue" />
                }
                else if (Value.Condition.CompareDataType != CompareDataType.DateTime)
                {
                    var decimalValue = 0m;
                    if(!decimal.TryParse(Value.Condition.Value, out decimalValue))
                    {
                        Value.Condition.Value = decimalValue.ToString();
                    }
                    <AntDesign.InputNumber
                        Disabled="ReadOnly"
                        Style="width:100%"
                        Size="small"
                        TValue="decimal"
                        OnChange="OnDecimalChange"
                        @bind-Value="decimalValue" />
                }
                else
                {
                    var dateTimeValue = DateTime.Today;
                    if (!DateTime.TryParse(Value.Condition.Value, out dateTimeValue))
                    {
                        Value.Condition.Value = DateTime.Today.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    <DatePicker TValue="DateTime" OnChange="OnDateTimeChange" @bind-Value="dateTimeValue" Size="small" Disabled="ReadOnly" />
                }
            </AntDesign.Col>
        }
        else if (Value.Condition.CompareDataType == CompareDataType.DataDictionary
            || Value.Condition.CompareDataType == CompareDataType.Enum)
        {
            <AntDesign.Col Span="5">
                <Select TItem="CompareType"
                    Disabled="ReadOnly"
                    Size="small"
                    TItemValue="CompareType"
                    PlaceHolder="请选择比较方式"
                    OnSelectedItemChanged="OnCompareTypeChange"
                    @bind-Value="Value.Condition.CompareType">
                    <SelectOptions>
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.Equals"
                            Label="等于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.NotEmpty"
                            Label="不等于" />
                    </SelectOptions>
                </Select>
            </AntDesign.Col>
            <AntDesign.Col Span="10">
                @if (Value.Condition.CompareDataType == CompareDataType.Enum)
                {
                    var enumValue = 0;
                    if(!int.TryParse(Value.Condition.Value, out enumValue))
                    {
                        Value.Condition.Value = enumValue.ToString();
                    }
                    <EnumTypeSelect
                        Disabled="ReadOnly"
                        Size="small"
                        DataSourceType="_CurrentField?.DataSourceType"
                        @bind-Value="enumValue"
                        OnSelectedItemChanged="OnEnumChange" />
                }
                else
                {
                    Guid? guidValue = null;
                    if(!Value.Condition.Value.IsNullOrWhiteSpace() && Guid.TryParse(Value.Condition.Value, out var _guid))
                    {
                        guidValue = _guid;
                    }
                    else
                    {
                        Value.Condition.Value = null;
                    }
                    <NNameValueDataSourceTypeSelect
                        Disabled="ReadOnly"
                        Size="small"
                        DataSourceType="_CurrentField?.DataSourceType"
                        @bind-Value="guidValue"
                        OnSelectedItemChanged="OnDataDictionaryChange" />
                }
            </AntDesign.Col>
        }
        else
        {
            <AntDesign.Col Span="5">
                <Select
                    Disabled="ReadOnly"
                    Size="small"
                    TItem="CompareType"
                    TItemValue="CompareType"
                    PlaceHolder="请选择比较方式"
                    OnSelectedItemChanged="OnCompareTypeChange"
                    @bind-Value="Value.Condition.CompareType">
                    <SelectOptions>
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.Equals"
                            Label="等于" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.Contains"
                            Label="包含" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.Empty"
                            Label="为空" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.NotEmpty"
                            Label="不为空" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.HasValue"
                            Label="有值" />
                        <SelectOption
                            TItem="CompareType"
                            TItemValue="CompareType"
                            Value="CompareType.NotHasValue"
                            Label="没值" />
                    </SelectOptions>
                </Select>
            </AntDesign.Col>
            <AntDesign.Col Span="10">
                @if (Value.Condition.CompareType != CompareType.HasValue
                    && Value.Condition.CompareType != CompareType.NotHasValue
                    || Value.Condition.CompareType != CompareType.Empty
                    && Value.Condition.CompareType != CompareType.NotEmpty)
                {
                    <Input Size="small" TValue="string" OnChange="OnStringChange" @bind-Value="Value.Condition.Value" ReadOnly="ReadOnly" />
                }
            </AntDesign.Col>
        }
    }
    else
    {
        <AntDesign.Col Span="24">
            <ConditionView ConditionFields="Fields" @bind-Value="Value" ReadOnly="ReadOnly" />
        </AntDesign.Col>
    }
</Row>
